package com.eso.haBank.domain

/**
 * 部门机构表Domain类
 *   机构由后台系统自动添加，前台进行新增机构归属关系设置
 */

import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString

@EqualsAndHashCode
@ToString(includeNames = true, includeFields = false, excludes = 'metaClass,beforeInsert,beforeUpdate')
class Department implements Serializable {

    String jgm;
    String jgjc;
    String jgbz;//机构标志
    String jglx;//机构类型

    String comment;

    String obligateField1;//预留字段1
    String obligateField2;//预留字段2
    String obligateField3;//预留字段3

    String createUser;
    Date createTime;
    String updateUser;
    Date updateTime;

    static belongsTo = [parentDept: Department]
    static hasMany = [users: Employee]

    static constraints = {
        jgm(blank: false, maxSize: 8, unique: true)
        jgjc(blank: false, maxSize: 20)
        jgbz(blank: false, maxSize: 1, inList: ['1', '2'])
        jglx(blank: false, maxSize: 1)

        comment(nullable: true, maxSize: 200)

        obligateField1(nullable: true, maxSize: 500)
        obligateField2(nullable: true, maxSize: 500)
        obligateField3(nullable: true, maxSize: 500)

        createUser(blank: false, maxSize: 10)
        createTime(nullable: true)
        updateUser(blank: false, maxSize: 10)
        updateTime(nullable: true)
    }

    def beforeInsert = {
        createTime = new Date()
        updateTime = new Date()
    }

    def beforeUpdate = {
        updateTime = new Date()
    }

    static mapping = {
        table 'sys_department'
        version false
        users joinTable: [name: 'sys_department_and_employee', column: 'employee_id', key: 'department_id']

        parentDept column: 'sjjgm'
    }
}
